package net.wofly.sale.signin.validator;


import net.wofly.sale.signin.domain.SignIn;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author siqingwei
 */
public class SignInValidator {
    
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateGetSignInParams(String userID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("员工ID不能为空").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateSignInParams(SignIn signIn) {
        StringBuffer stringBuffer = new StringBuffer();
        if (signIn == null) {
            stringBuffer.append("签到对象（signIn）不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(signIn.getUserID())) {
                stringBuffer.append("员工ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(signIn.getTitle())) {
                stringBuffer.append("标题不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(signIn.getPosition())) {
                stringBuffer.append("签到位置不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(signIn.getPositionName())) {
                stringBuffer.append("签到位置名称不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }

    public static String validateUploadPicParams(MultipartFile file) {
        StringBuffer stringBuffer = new StringBuffer();
        if (file == null) {
            stringBuffer.append("文件不能为空").append(lineSeparator);
        } else {
            long fileSize = file.getSize();
            long maxFileSize = 5 * 1024 * 1024;
            if (fileSize > maxFileSize) {
                stringBuffer.append("文件不能大于5Mb").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
}
